package net.dodoman.collection;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Stack;
import java.util.Vector;

public class CollectionTest {

	private static List<Object> linkedList, arrayList, vector, stack;

	private static Map<Object, Object> hashTable, hashMap;

	private static Set<Object> hashSet;

	/**
	 * 静态初始化块
	 */
	static {
		linkedList = new LinkedList<Object>();
		arrayList = new ArrayList<Object>();
		vector = new Vector<Object>();
		stack = new Stack<Object>();
		hashTable = new java.util.Hashtable<Object, Object>();
		hashMap = new HashMap<Object, Object>();
		hashSet = new HashSet<Object>();
	}

	/** Singleton Instance */
	private static CollectionTest collectionTest;

	public static void main(String[] args) {
		// testList();
		testSet();
		// testMap();
	}

	/**
	 * 构造器
	 */
	private CollectionTest() {
	}

	/**
	 * 获取实例
	 * 
	 * @return
	 */
	private static CollectionTest getInstance() {
		if (collectionTest == null)
			collectionTest = new CollectionTest();
		return collectionTest;

	}

	/**
	 * List接口类测试方法
	 */
	private static void testList() {
		Object o = new Object();
		linkedList.add(o);
		linkedList.add(o);
		arrayList.add(o);
		arrayList.add(o);
		vector.add(o);
		vector.add(o);
		stack.add(o);
		stack.add(o);
		linkedList.add(null);
		arrayList.add(null);
		vector.add(null);
	}

	/**
	 * Map接口类测试方法
	 */
	private static void testMap() {
		hashMap.put(null, null);
		hashTable.put(null, null);
	}

	/**
	 * Set接口类测试方法
	 */
	private static void testSet() {
		Object o = new Object();
		hashSet.add(o);
		hashSet.add(o);
		String abc = "abc";
		hashSet.add(abc);
		hashSet.add(abc);
		Iterator<Object> it = hashSet.iterator();
		while (it.hasNext()) {
			Object myO = it.next();
			System.out.println(myO.toString());
		}
	}
}
